<?php
namespace App\Http\Controllers\Admin;

use App\Models\Admin;
use App\Http\Controllers\Controller;

class LoginController extends Controller {

    /**
     * 管理端登录
     * @author sweeter 2022-01-24
     * @method      [GET|POST] /api/Admin/login
     * @return      Object
     */
    public function login () {

        $credentials = request(['username', 'password']);
        if (!$token = auth('admin')->attempt($credentials)) {
            return $this->error('token not found.');
        }

        $user = auth('admin')->user();
        if (empty($user)) {
            return $this->error('user not found.');
        }

        return $this->success([
            'token' => $token,
        ]);
    }
}